using System;
using System.Text;
using System.Text.RegularExpressions;
using System.Web.Configuration;
using System.Web.Security;
namespace CommandLib.Base
{
	public static class StringHelper
	{
		public static string InputText(this string input_text)
		{
			return input_text.InputText(input_text.Length);
		}
		public static string InputText(this string input_text, int max_length)
		{
			StringBuilder stringBuilder = new StringBuilder();
			if (input_text != null && input_text != string.Empty)
			{
				input_text = input_text.Trim();
				if (input_text.Length > max_length)
				{
					input_text = input_text.Substring(0, max_length);
				}
				for (int i = 0; i < input_text.Length; i++)
				{
					char c = input_text[i];
					if (c != '"')
					{
						switch (c)
						{
							case '<':
							{
								stringBuilder.Append("");
								goto IL_E0;
							}
							case '=':
							{
								break;
							}
							case '>':
							{
								stringBuilder.Append("");
								goto IL_E0;
							}
							default:
							{
								switch (c)
								{
									case '{':
									{
										stringBuilder.Append("");
										goto IL_E0;
									}
									case '}':
									{
										stringBuilder.Append("");
										goto IL_E0;
									}
								}
								break;
							}
						}
						stringBuilder.Append(input_text[i]);
					}
					else
					{
						stringBuilder.Append("");
					}
					IL_E0:;
				}
				stringBuilder.Replace("'", " ");
			}
			return stringBuilder.ToString();
		}
		public static string ToDBC(this string input)
		{
			char[] array = input.ToCharArray();
			for (int i = 0; i < array.Length; i++)
			{
				if (array[i] == '\u3000')
				{
					array[i] = ' ';
				}
				else
				{
					if (array[i] > '＀' && array[i] < '｟')
					{
						array[i] -= 'ﻠ';
					}
				}
			}
			return new string(array);
		}
		public static string Encrypt(this string input)
		{
			return FormsAuthentication.HashPasswordForStoringInConfigFile(input, FormsAuthPasswordFormat.MD5.ToString());
		}
		public static byte Asc(this string str)
		{
			return Encoding.ASCII.GetBytes(str)[0];
		}
		public static byte[] AscAll(this string str)
		{
			return Encoding.ASCII.GetBytes(str);
		}
		public static bool IsRightIP(this string ip)
		{
			bool result;
			if (Regex.IsMatch(ip, "[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}"))
			{
				string[] array = ip.Split(new char[]
				{
					'.'
				});
				for (int i = 0; i < array.Length; i++)
				{
					if (int.Parse(array[i]) > 256)
					{
						result = false;
						return result;
					}
				}
				result = true;
			}
			else
			{
				result = false;
			}
			return result;
		}
	}
}
